const shareUtil = require('../../../utils/shareUtil.js');
var t,
o = require("../utils/js/interopRequireDefault"),
e= require("../utils/js/defineProperty"),
f = o(require("../utils/js/paint"))
const  app= getApp();
var imgUrl=app.globalData.imgUrl
Page({
    data: (
      t = {
        canvasInfo: {
            id: "mycanvas",
            width: 200,
            height: 200
        },
        QrcodeInfo: {
            text: "",
            background: "#ffffff",
            foreground: "#000000"
        },
        systemInfo: {
            width: 320,
            height: 568
        },
        color_array: [ "白", "黑", "红", "橙", "黄", "绿", "青", "蓝", "紫" ],
        color: [ "#ffffff", "#000000", "#ff0000", "#ff8800", "#ffff00", "#00ff00", "#00fff0", "#0000ff", "#ff00ff" ],
        foreColorIndex: 1,
        bgColorIndex: 0,
        colorName: "白色"
      }, 
      e(t, "color", "#ffffff"), 
      e(t, "colorSelectCount", false), 
      e(t, "colorArray", [ {
          title: "嫣红",
          bgcolor: "#e54d42",
          color: "#ffffff"
      }, {
          title: "桔橙",
          bgcolor: "#f37b1d",
          color: "#ffffff"
      }, {
          title: "明黄",
          bgcolor: "#fbbd08",
          color: "#343333"
      }, {
          title: "橄榄",
          bgcolor: "#8dc63f",
          color: "#ffffff"
      }, {
          title: "森绿",
          bgcolor: "#39b54a",
          color: "#ffffff"
      }, {
          title: "天青",
          bgcolor: "#1cbbb4",
          color: "#ffffff"
      }, {
          title: "海蓝",
          bgcolor: "#0081ff",
          color: "#ffffff"
      }, {
          title: "姹紫",
          bgcolor: "#6739b6",
          color: "#ffffff"
      }, {
          title: "木槿",
          bgcolor: "#9c26b0",
          color: "#ffffff"
      }, {
          title: "桃粉",
          bgcolor: "#e03997",
          color: "#ffffff"
      }, {
          title: "棕褐",
          bgcolor: "#a5673f",
          color: "#ffffff"
      }, {
          title: "玄灰",
          bgcolor: "#8799a3",
          color: "#ffffff"
      }, {
          title: "纯黑",
          bgcolor: "#000000",
          color: "#ffffff"
      }, {
          title: "墨黑",
          bgcolor: "#333333",
          color: "#ffffff"
      }, {
          title: "雅白",
          bgcolor: "#ffffff",
          color: "#6f6f6f"
      } ]),
      e(t, "bgcolorName", "黑色"),
      e(t, "bgcolor", "#000000"), 
      e(t, "bgcolorSelectCount", false), 
      e(t, "content", "面包工具箱"), 
      e(t, "width", "178"), t),
    onLoad: function(t) {
        var that = this;
        wx.getSystemInfo({
            success: function(t) {
              that.setData({
                    "systemInfo.width": t.windowWidth,
                    "systemInfo.height": t.windowHeight,
                    "canvasInfo.width": t.windowWidth / 2,
                    "canvasInfo.height": t.windowWidth / 2
                });
            }
        }),
        this.saveAndGetData("", true);
    },
    onShow: function(t) {
        this.saveAndGetData("", true);
        var o = this.data.QrcodeInfo,
            e = this.data.canvasInfo;
        "" == o.text && (o.text = "面包工具箱"), (0, f.default)({
            width: e.width,
            height: e.height,
            canvasId: e.id,
            text: o.text,
            foreground: o.foreground,
            background: o.background
        });
    },
    saveQrcode: function() {
        var that = this;
        if (1 != app.getJur()) {
            var o = that.data.canvasInfo;
            wx.canvasToTempFilePath({
              canvasId: o.id,
              success: function(t) {
                  t.tempFilePath;
                  wx.saveImageToPhotosAlbum({
                      filePath: t.tempFilePath,
                      success: function(t) {
                          wx.showToast({
                              title: "保存成功",
                              icon: "none"
                          });
                      },
                      fail: function(t) {
                          console.log(t);
                      }
                  });
              }
          }, t)
        }
    },
    createQrcode: function() {
        var that = this, 
            o = that.data.width, 
            e = that.data.QrcodeInfo, 
            a = that.data.canvasInfo, 
            c = that.data.content;
        a.width = o,
        a.height = o, 
        that.setData({
          canvasInfo: a,
          "QrcodeInfo.text": c
      }), 
      (0, f.default)({
          width: a.width,
          height: a.height,
          canvasId: a.id,
          text: c,
          foreground: e.foreground,
          background: e.background
      }), 
      that.saveAndGetData(c, false)
    },
    saveAndGetData: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", o = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], that = this;
        console.log(arguments);
        0 == o ? wx.setStorage({
            key: "createQrcode_text",
            data: t
        }) : wx.getStorage({
            key: "createQrcode_text",
            success: function(t) {
              that.setData({
                    "QrcodeInfo.text": t.data
                });
            }
        });
    },
    inputSave: function(t) {
        this.setData({
            content: t.detail.value
        }), 
        this.saveAndGetData(t.detail.value, false), 
        this.createQrcode();
    },
    clicked: function(t) {
        var o = t.currentTarget.id;
        "wordColor" == o ? this.setData({
            colorSelectCount: true
        }) : "bgColor" == o && this.setData({
            bgcolorSelectCount: true
        });
    },
    chooseColor: function(t) {
        var o = t.detail, e = new Array();
        e = this.data.colorArray[o], this.setData({
            color: e.bgcolor,
            colorName: e.title,
            "QrcodeInfo.foreground": e.bgcolor
        }), this.createQrcode();
    },
    chooseBgcolor: function(t) {
        var o = t.detail, e = new Array();
        e = this.data.colorArray[o], this.setData({
            bgcolor: e.bgcolor,
            bgcolorName: e.title,
            "QrcodeInfo.background": e.bgcolor
        }), this.createQrcode();
    },
    changeWidth: function(t) {
        this.setData({
            width: t.detail.value
        }), this.createQrcode();
    },
    previewImage: function(t) {
        var o = this.data.canvasInfo;
        wx.canvasToTempFilePath({
            canvasId: o.id,
            success: function(t) {
                var o = t.tempFilePath, 
                e = [];
                e.push(o),
                 wx.previewImage({
                    urls: e
                });
            }
        }, this);
    },
    onShareAppMessage:shareUtil.shareConfig,
    onShareTimeline:shareUtil.shareConfig,
});